#include "logindialog.h"
#include "ui_logindialog.h"
#include <QMessageBox>
#include <QSettings>

LoginDialog::LoginDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LoginDialog)
{
    ui->setupUi(this);
}

LoginDialog::~LoginDialog()
{
    delete ui;
}



void LoginDialog::on_pushButton_clicked()
{
    QString username = ui->lineEdit->text().trimmed();
    QString password = ui->lineEdit_2->text().trimmed();

    if(username == ""||
       password == ""   )
    {
        QMessageBox::information(this, tr("error"), ("invalid username or password"));
        return;
    }


    QString sql = tr("select * from user where username = '%1' and password = '%2'").arg(username).arg(password);
    this->username = username;
    this->password = password;
    QSettings *settings = new QSettings("config.ini", QSettings::IniFormat);
    settings->setValue("username", username);
    settings->setValue("password", password);
    delete settings;
    close();
}

void LoginDialog::on_pushButton_2_clicked()
{

    close();
}
